package com.dept.controller;

import com.common.compoent.PrintWriter;
import com.common.pojo.Dept;
import com.common.service.DeptService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Str
 * @Date 2022/1/6 14:21
 * @Description :
 */
@RestController
public class DeptController implements DeptService {
    // 引入配置文件中的端口
    @Value("${server.port}")
    private String port;

    @Override
    public Dept getDeptById(@RequestParam("id") Integer id) {
        PrintWriter.prtMark("DeptController.getDeptById.id：" + id);
        PrintWriter.prtMark("port：" + port);
        return new Dept(id, "top", "top_1", "本部", port, "1", "高级");
    }

    @Override
    public String getLongTime() {
        long startTime = System.currentTimeMillis();
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long endTime = System.currentTimeMillis();
        return "消耗时间：" + (endTime - startTime) + "ms";
    }

    @Override
    public String getShortTime() {
        long startTime = System.currentTimeMillis();
        long endTime = System.currentTimeMillis();
        return "消耗时间：" + (endTime - startTime) + "ms";
    }

    @Override
    public String divide(@RequestParam("num") Integer num) {
        return String.valueOf(10 / num);
    }
}
